<template>
  <div id="orderlist" style="position: relative;">
          <el-table id="mytable" :data="orderdata" style="width: 100%" :height="dtheight" :header-cell-style="{background:'#4F81BC',color:'white'}"
           :row-class-name="tableRowClassName"  :border="true">

                <el-table-column :label="variable_name4 + '标识'"  align='center' width="150">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.pid }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="会员账号"  align='center'  width="170px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.telphone }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="会员名称"  align='center'  width="170px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.nickname }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="收获时间"  align='center'  width="170px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.time }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '等级'"  align='center'  width="170px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.level }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '价值'"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.price }}</span>
                    </template>
                </el-table-column>
                <el-table-column :label="variable_name4 + '剩余价值'"  align='center'  width="170px" >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.surplus_price }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="收货地址"  align='center'  width="300px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.address_region }} {{ scope.row.address_detail }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="收货姓名"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.address_username }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="收货手机号"  align='center'  width="170px">                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.address_telphone }}</span>
                    </template>
                </el-table-column>

                
                <el-table-column label="订单状态"  align='center'   width="150px">                   
                    <template slot-scope="scope">                   
                        <span v-if=" scope.row.status == 'TAKE_DELIVERY_MANUAL'">发货订单</span>
                        <span v-if=" scope.row.status == 'TAKE_DELIVERY_AUTO'">发货订单</span>
                        <span v-if=" scope.row.status == 'APPEALING'">赎回订单</span>
                        <span v-if=" scope.row.status == 'GAMEOVER'">已完成</span>
                    </template>
                </el-table-column>
               
               <el-table-column label="收获状态"  align='center'  width="150px" >                   
                    <template slot-scope="scope">                   
                        <span v-if=" scope.row.status == 'TAKE_DELIVERY_MANUAL'">手动收获</span>
                        <span v-if=" scope.row.status == 'TAKE_DELIVERY_AUTO'">自动收获</span>
                        <span v-if=" scope.row.status == 'APPEALING'">自动收获</span>
                        <span v-if=" scope.row.status == 'GAMEOVER'">已完成</span>
                    </template>
                </el-table-column>



                 <el-table-column label="是否发货"  align='center'   width="150px">                   
                    <template slot-scope="scope">                   
                        <span v-if="scope.row.delivered == 1">已发货</span>
                        <span v-else>待发货</span>
                    </template>
                </el-table-column>
                

                 <el-table-column label="操作" align='center' width="350px" fixed="right">
                    <template slot-scope="scope">
                        <!-- 手动发货 -->
                        <span v-if="scope.row.status == 'TAKE_DELIVERY_MANUAL'" > 
                            <span v-if="scope.row.address_finish == 1">
                                <el-button size="mini"  type="primary"  plain @click="bh_but(scope.row.orderno)"  v-if="scope.row.delivered == 0">驳回</el-button> 
                                <el-button size="mini"  type="primary"  plain  @click="substitution_but(scope.row)"  v-if="scope.row.delivered == 0">置换{{ variable_name1 }}</el-button> 
                                <el-button size="mini"  type="primary"  plain  @click="add_mx_but(scope.row)">明细</el-button> 
                                <el-button size="mini"  type="primary"  plain @click="add_fh_but(scope.row)">发货</el-button> 
                            </span>
                        </span>
                        
                         <!-- 自动发货 不带赎回 -->
                        <span v-if="scope.row.status == 'TAKE_DELIVERY_AUTO'" > 
                            <el-button size="mini"  type="primary"  plain  @click="bh_but(scope.row.orderno)" v-if="scope.row.delivered == 0">驳回</el-button> 
                            <el-button size="mini"  type="primary"  plain   @click="substitution_but(scope.row)" v-if="scope.row.delivered == 0">置换{{ variable_name1 }}</el-button>
                            <span v-if="scope.row.address_finish == 1">
                                <el-button size="mini"  type="primary"  plain  @click="add_mx_but(scope.row)">明细</el-button> 
                                <el-button size="mini"  type="primary"  plain @click="add_fh_but(scope.row)">发货</el-button> 
                            </span>
                        </span>


                          <!-- 自动发货 带赎回 -->
                        <span v-if="scope.row.status == 'APPEALING'" > 
                            <span v-if="scope.row.address_finish == 1">
                                <el-button size="mini"  type="primary"  plain  @click="agree_sh(scope.row.orderno)">同意赎回</el-button> 
                                <el-button size="mini"  type="primary"  plain  @click="refuse_sh(scope.row.orderno)">拒绝赎回</el-button> 
                                <el-button size="mini"  type="primary"  plain  @click="add_mx_but(scope.row)">明细</el-button> 
                            </span>
                        </span>

                    </template>
                </el-table-column>
  
            </el-table> 


    


    <!-- 发货 -->
    <el-dialog title="发货" :visible.sync="add_fh"  width="500px">
        <div style="width:100%;"> 

        <el-form ref="form"   label-width="100px" style="width:100%;">
            <el-form-item label="发货价值">
                <el-input v-model="fh_form.send_price" placeholder="发货价值"></el-input>
            </el-form-item>                                   
        </el-form>
        <el-form ref="form"   label-width="100px" style="width:100%;">
            <el-form-item label="快递公司">
                <el-input v-model="fh_form.express_company" placeholder="快递公司"></el-input>
            </el-form-item>                                   
        </el-form>
        <el-form ref="form"   label-width="100px" style="width:100%;">
            <el-form-item label="快递单号">
                <el-input v-model="fh_form.express_number" placeholder="快递单号"></el-input>
            </el-form-item>                                   
        </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="fh_but_qr">确认</el-button>
            </div>

        </div> 
    </el-dialog>



        <!-- 发货明细 -->
    <el-dialog title="发货明细" :visible.sync="add_mx"  width="50%">
        <div style="width:100%;"> 

            <el-table :data="mx_data" style="width: 100%;height:400px;"  :header-cell-style="{background:'#eef1f6',color:'#606266'}">

              
                <el-table-column label="发货时间"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.time }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="快递公司"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.express_company }}</span>
                    </template>
                </el-table-column>
                 <el-table-column label="快递单号"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.express_number }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="发货价值"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.price }}</span>
                    </template>
                </el-table-column>
  
            </el-table>  
                  
        </div> 
    </el-dialog>



      <!-- 置换果米 -->
    <el-dialog :title="'置换' + variable_name1" :visible.sync="substitution_mtk"  width="400px">
        <div style="width:100%;"> 

        <el-form ref="form"   label-width="0px" style="width:100%;">
            <el-form-item label="">
                <el-input v-model="substitution_form.number" placeholder="数量"></el-input>
            </el-form-item>                                                                        
        </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="substitution_qr()">确认</el-button>
            </div>

        </div> 
    </el-dialog>


   </div>
</template>

<script>

export default {
   name: 'orderlist',
   props:{
      orderdata:{  
        //type:Array,
       default:()=>[]
     },
  },
  data () {
    return {
        dtheight:'500',  //窗口高度
        add_fh:false,
        my_orderno:'',
        fh_form:{
           send_price:'',
           express_company:'',
           express_number:''
        },
        add_mx:false,
        mx_data:[],
        substitution_mtk:false,
        substitution_form:{
              number:''
        }
    }
  },
   components:{

  },
  created(){
     this.dtheight = window.innerHeight - 303
      
  },
  mounted (){
    
  },
  methods: {
 
    add_fh_but(row){
        this.add_fh = true
        this.my_orderno = row.orderno
        this.fh_form.send_price = ''
        this.fh_form.express_company = ''
        this.fh_form.express_number = ''
    },
    fh_but_qr(){
         this.post("/order/deliver", {
                    orderno:this.my_orderno,
                    send_price:this.fh_form.send_price,
                    express_company:this.fh_form.express_company,
                    express_number:this.fh_form.express_number,
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.add_fh = false
                        this.$emit('up_list_fun')
                    }else {
                      this.open1(res.message,'warning')
                    }

             })
    },
    add_mx_but(row){
         this.add_mx = true
         this.post("/order/listOfDeliverLog", {
                orderno:row.orderno
                }).then(res => {
                this.mx_data = res.result

                //console.log(res)
       })
       
    },
    bh_but(orderno){  //是否驳回


       this.$confirm('是否驳回此订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            
             this.post("/order/refuseHarvestRequest", {
                    orderno:orderno,
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    }else {
                    this.open1(res.message,'warning')
                }

             })

        }).catch(() => {
        //   this.$message({
        //     type: 'info',
        //     message: '已取消解冻'
        //   });          
        });

    },
    agree_sh(orderno){  //同意赎回
    
        
       this.$confirm('是否同意赎回此订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            
              this.post("/order/agreeRedeem", {
                    orderno:orderno,
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    }else {
                    this.open1(res.message,'warning')
                }

             })

        }).catch(() => {
        //   this.$message({
        //     type: 'info',
        //     message: '已取消解冻'
        //   });          
        });

    

    },
    refuse_sh(orderno){  //拒绝赎回


     this.$confirm('是否拒绝赎回此订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            
              this.post("/order/refuseRedeem", {
                    orderno:orderno,
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    }else {
                    this.open1(res.message,'warning')
                }

             })

        }).catch(() => {
        //   this.$message({
        //     type: 'info',
        //     message: '已取消解冻'
        //   });          
        });

        
    },
    substitution_but(row){
        this.substitution_form.number = ''
        this.my_orderno = row.orderno
        this.substitution_mtk = true
    },
    substitution_qr(){

        this.$confirm('是否置换果米, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            
              this.post("/order/displaceToKmb", {
                    orderno:this.my_orderno,
                    num:this.substitution_form.number
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    this.substitution_mtk = false
                    }else {
                    this.open1(res.message,'warning')
                }

             })

        }).catch(() => {
               
        });

    }


  }
}
</script>


<style scoped>

</style>